package view;

import controller.MoodleCategoryWS;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import model.MoodleCategory;
import model.MoodleException;
import org.json.simple.parser.ParseException;

/**
 * Bean with category set, is used by categories.jsp.
 *
 * @author kgp
 */
public class MoodleCategoriesBean {

    private Set<MoodleCategory> categories;

    /**
     * Constructor getting all categories to the categories field of the bean.
     *
     * @throws model.MoodleException
     */
    public MoodleCategoriesBean() throws MoodleException, ParseException {
        MoodleCategoryWS categoryWS = new MoodleCategoryWS();
        Map<String, String> criteria = new HashMap<String, String>();
        /*If criteria is empty - returns all categories*/
//        criteria.put("id", "3");  //Institut upravlinnya categories
        byte addSubcategories = 1;   //for include subcategories
//        byte addSubcategories = 0;   //for exclude subcategories
        Set<MoodleCategory> rawCategories = categoryWS.getCategories(criteria, addSubcategories);
        this.categories = rawCategories;
    }

    public Set<MoodleCategory> getCategories() {
        return categories;
    }

    public void setCategories(Set<MoodleCategory> categories) {
        this.categories = categories;
    }
}
